package top.continew.minithreadpool.concurrent;

import top.continew.minithreadpool.factory.DefaultThreadFactory;
import top.continew.minithreadpool.policy.AbortPolicy;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * 线程池工厂类
 */
public class ThreadPoolFactory {
    /**
     * 创建固定大小的线程池
     *
     * @param nThreads 线程池大小
     * @return 线程池
     */
    public static ThreadPool createFixedThreadPool(int nThreads) {
        return new ThreadPool(
                nThreads, nThreads, 0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(100),
                new DefaultThreadFactory(),
                new AbortPolicy()
        );
    }

    public static ThreadPool createCachedThreadPool() {
        return new ThreadPool(
                0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(100),
                new DefaultThreadFactory(),
                new AbortPolicy()
        );
    }

    public static ThreadPool createSingleThreadExecutor() {
        return new ThreadPool(
                1, 1, 0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(100),
                new DefaultThreadFactory(),
                new AbortPolicy()
        );
    }
}
